package com.action.log;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.log.LogType;
import com.business.log.LogTypeBus;
import com.config.SystemGlobals;

public class AddLogType extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);
		String logtypeName = request.getParameter("logtypename");
		String logtypeMemo = request.getParameter("logtypememo");
		String username = request.getParameter("username");
		LogType lt = new LogType();
		lt.setLogtypeMemo(logtypeMemo);
		lt.setLogtypeName(logtypeName);
		lt.setUsername(username);
		LogTypeBus ltb = new LogTypeBus();
		String action = request.getParameter("action");
		if (action.equals("update")) {
			String typeId = request.getParameter("id");
			ltb.update(lt, typeId);
			RequestDispatcher rd = request
					.getRequestDispatcher("/user/showlist.jsp");
			rd.forward(request, response);
		}
		if (action.equals("add")) {
			ltb.add(lt);
			out
					.print("<script>alert(\"您成功地添加了一个日志分类\");window.location=\""+request.getContextPath()+"/user/addlog.jsp\";</script>");
			out.close();
		}
	}
}
